<template>
  <!-- 添加或修改请购单（自制/采购/外协）对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="巡检质检记录" prop="xunjianFile">
                <image-upload v-model="form.xunjianFile" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="尺寸检查" name="second">
          <el-row :gutter="20">
            <el-col :span="24">
              <FactoryTestSizeList :Row="Row" />
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="抽样检测" name="third">
          <el-row :gutter="20">
            <el-col :span="24">
              <FactoryTestSampleList :Row="Row" />
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="镀锌质量" name="fourth">
          <el-row :gutter="20">
            <el-col :span="24">
              <FactoryTestZnList :Row="Row" />
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="外观检查" name="five">
          <el-row :gutter="20">
            <el-col :span="24">
              <FactoryTestSurfaceList :Row="Row" />
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="机械试验-悬垂线夹和连接金具" name="six">
          <el-row :gutter="20">
            <el-col :span="24">
              <FactoryTestMachineryLinkList :Row="Row" />
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="机械试验-间隔棒" name="seven">
          <el-row :gutter="20">
            <el-col :span="24">
              <FactoryTestMachineryStickList :Row="Row" />
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="机械试验-防振锤" name="eight">
          <el-row :gutter="20">
            <el-col :span="24">
              <FactoryTestMachineryHammerList :Row="Row" />
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {
    addAction,
    getById,
    updateAction
  } from '@/api/manage';
  import moment from 'moment';
  import FactoryTestSizeList from '../../factory/factoryTestSize/FactoryTestSizeList.vue';
  import FactoryTestSampleList from '../../factory/factoryTestSample/FactoryTestSampleList.vue';
  import FactoryTestZnList from '../../factory/factoryTestZn/FactoryTestZnList.vue';
  import FactoryTestSurfaceList from '../../factory/factoryTestSurface/FactoryTestSurfaceList.vue';
  import FactoryTestMachineryLinkList from '../../factory/factoryTestMachineryLink/FactoryTestMachineryLinkList.vue';
  import FactoryTestMachineryStickList from '../../factory/factoryTestMachineryStick/FactoryTestMachineryStickList.vue';
  import FactoryTestMachineryHammerList from '../../factory/factoryTestMachineryHammer/FactoryTestMachineryHammerList.vue';
  export default {
    name: "XunjianForm",
    components: {
      FactoryTestSizeList,
      FactoryTestSampleList,
      FactoryTestZnList,
      FactoryTestSurfaceList,
      FactoryTestMachineryLinkList,
      FactoryTestMachineryStickList,
      FactoryTestMachineryHammerList
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        activeName: "first",
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        url: {
          getById: '/factoryProduceSaleAll/factoryProduceSaleAll/',
          add: '/factoryProduceSaleAll/factoryProduceSaleAll/add',
          edit: '/factoryProduceSaleAll/factoryProduceSaleAll/edit',
        },
        Row: {}
      };
    },
    created() {

    },
    methods: {
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          xunjianFile: null,
        };
        this.resetForm("form");
      },
      /** 修改按钮操作 */
      xunjianShow(row) {
        this.reset();
        const id = row.id || this.ids;
        this.Row = row
        getById(this.url.getById, id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "上传巡检质检单";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateAction(this.url.edit, this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.$emit('ok');
              });
            } else {
              addAction(this.url.add, this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.$emit('ok');
              });
            }
          }
        });
      },
    }
  };
</script>
